package com.ruoyi.repair.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.repair.domain.PropertyInspectionRecord;
import com.ruoyi.repair.service.IPropertyInspectionRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 巡检记录Controller
 * 
 * @author ruoyi
 * @date 2025-10-27
 */
@RestController
@RequestMapping("/repair/recordIns")
public class PropertyInspectionRecordController extends BaseController
{
    @Autowired
    private IPropertyInspectionRecordService propertyInspectionRecordService;

    /**
     * 查询巡检记录列表
     */
    @PreAuthorize("@ss.hasPermi('repair:recordIns:list')")
    @GetMapping("/list")
    public TableDataInfo list(PropertyInspectionRecord propertyInspectionRecord)
    {
        startPage();
        List<PropertyInspectionRecord> list = propertyInspectionRecordService.selectPropertyInspectionRecordList(propertyInspectionRecord);
        return getDataTable(list);
    }

    /**
     * 导出巡检记录列表
     */
    @PreAuthorize("@ss.hasPermi('repair:recordIns:export')")
    @Log(title = "巡检记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PropertyInspectionRecord propertyInspectionRecord)
    {
        List<PropertyInspectionRecord> list = propertyInspectionRecordService.selectPropertyInspectionRecordList(propertyInspectionRecord);
        ExcelUtil<PropertyInspectionRecord> util = new ExcelUtil<PropertyInspectionRecord>(PropertyInspectionRecord.class);
        util.exportExcel(response, list, "巡检记录数据");
    }

    /**
     * 获取巡检记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('repair:recordIns:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(propertyInspectionRecordService.selectPropertyInspectionRecordByRecordId(recordId));
    }

    /**
     * 新增巡检记录
     */
    @PreAuthorize("@ss.hasPermi('repair:recordIns:add')")
    @Log(title = "巡检记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PropertyInspectionRecord propertyInspectionRecord)
    {
        return toAjax(propertyInspectionRecordService.insertPropertyInspectionRecord(propertyInspectionRecord));
    }

    /**
     * 修改巡检记录
     */
    @PreAuthorize("@ss.hasPermi('repair:recordIns:edit')")
    @Log(title = "巡检记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PropertyInspectionRecord propertyInspectionRecord)
    {
        return toAjax(propertyInspectionRecordService.updatePropertyInspectionRecord(propertyInspectionRecord));
    }

    /**
     * 删除巡检记录
     */
    @PreAuthorize("@ss.hasPermi('repair:recordIns:remove')")
    @Log(title = "巡检记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(propertyInspectionRecordService.deletePropertyInspectionRecordByRecordIds(recordIds));
    }
}
